package com.zjitc.service.imp;

import com.github.pagehelper.PageHelper;
import com.zjitc.dao.CollectionDao;
import com.zjitc.dao.ProductDao;
import com.zjitc.model.Collection;
import com.zjitc.model.Product;
import com.zjitc.service.CollectionService;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by LWW on 2018/6/5.
 */
@Service
public class CollectionServiceImp implements CollectionService {
    @Autowired
    public CollectionDao collectionDao;

    @Autowired
    public ProductDao productDao;

    @Override
    public void collection(String pid, String uid, String collectionId) {
        collectionDao.collection(pid,uid,collectionId);
    }

    @Override
    public void deleteCollection(String pid, String uid) {
        collectionDao.deleteCollection(pid,uid);
    }

    @Override
    public List<Product> findAllCollection(String uid) {
      List<Collection> collections=collectionDao.findAllCollection(uid);
      List<Product> products = new ArrayList<Product>();
      for (Collection product : collections) {
        Product p = productDao.findByPid(product.getPid());

        products.add(new Product(p.getPid(),p.getPname(),p.getMarket_price(),p.getShop_price(),p.getPimage(),p.getPdate(),p.getIs_hot(),p.getPdesc(),p.getPflag()));
      }
      return products;
    }

  @Override
  public Product findByPid(String pid) {
    Product product=collectionDao.findByPid(pid);
    return product;
  }
}
